<template>
	<view class="prefecture">
		<!-- #ifdef APP-PLUS -->
		<Hearder :name="'专区时间管理'"></Hearder>
		<!-- #endif -->
		<view class="timelist bgbottom" v-for="(item,index) in statuslist" :key="index">
			<view class="timeevery">
				<view>{{item.title}}:</view>
				<view>
					<u-switch v-model="item.value" inactiveColor="#eee" activeColor="#28BA9B" @change="change(item.open_status,item.specialarea_type)"></u-switch>
				</view>
			</view>
			<view class="timeevery" @click="toPage('spacetime?specialarea_type='+item.specialarea_type+'&type=1')">
				<view>预约设置:</view>
				<view>
					<text v-if="item.time.reserve_start_time_text">{{item.time.reserve_start_time_text}}-{{item.time.reserve_end_time_text}}</text>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
			</view>
			<view class="timeevery" @click="toPage('spacetime?specialarea_type='+item.specialarea_type+'&type=2')">
				<view>时间设置:</view>
				<view>
					<text v-if="item.time.start_time">{{item.time.start_time}}-{{item.time.end_time}}</text>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
			</view>
			<view class="timeevery">
				<view>预约抢单数:</view>
				<view>
					<u-number-box :min="0" v-model="item.num" @change="(e)=>valChange(e,item.specialarea_type)"></u-number-box>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				statuslist:[],
				space_id:'',
				choosenum:1,
				val:[0,0]
			}
		},
		onLoad(options) {
			this.space_id = options.space_id
		},
		onShow() {
			this.getinit()
		},
		methods:{
			getinit(){
				this.request('/goods/getLootList',{
					type:1
				}).then(res => {
					if(res.data.code==1){
						res.data.data.map((item,index)=>{
							if(item.open_status==10){
								item.value = true
							}else{
								item.value = false
							}
						})
						this.statuslist = res.data.data
					}
				})
			},
			valChange(e,specialarea_type) {
				// console.log('当前值为: ' + e.value)
				this.request('/space/toSpace',{
					num:e.value,
					specialarea_type:specialarea_type,
					space_id:this.space_id
				}).then(res => {
					if(res.data.code==1){
						this.$tip(res.data.msg)
						this.getinit()
					}else{
						this.$tip(res.data.msg)
					}
				})
			},
			change(open_status,specialarea_type){
				if(open_status==10){
					open_status=20
				}else if(open_status==20){
					open_status=10
				}
				this.request('/space/toSpace',{
					open_status:open_status,
					specialarea_type:specialarea_type,
					space_id:this.space_id
				}).then(res => {
					if(res.data.code==1){
						this.$tip(res.data.msg)
						this.getinit()
					}else{
						this.$tip(res.data.msg)
					}
				})
			},
			toPage(route){
				uni.navigateTo({
				    url: route
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.prefecture{
		.timelist{
			padding: 0 4%;
			.timeevery{
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 110rpx;
				border-bottom: 1rpx solid #eee;
				&:last-of-type{
					border-bottom: none;
				}
				text{
					margin-right: 8rpx;
				}
			}
		}
	}
</style>